home *** CD-ROM | disk | FTP | other *** search
- Path: easy.in-chemnitz.de!mkmk!floh
- From: floh@mkmk.in-chemnitz.de (Andre Weissflog)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Redirecting
- Message-ID: <u6j+x*-D0@mkmk.in-chemnitz.de>
- Date: Tue, 23 Jan 1996 23:34:54 CET
- Reply-To: floh@mkmk.in-chemnitz.de
- References: <9601231531.AA0006s@cliffe.demon.co.uk>
- Distribution: world
- Organization: private uucp site
- X-Newsreader: Arn V 1.04
-
- In article <9601231531.AA0006s@cliffe.demon.co.uk>, Steven Chapman writes:
-
- > Thanks for the previous help
- >
- > What i now need is how to declare BPTR so i can use the file it opens
- > globally thoughtout my program.
- >
- > As i can only use this within the same { }.
- >
- > BPTR fh;
- >
- > if(!(fh = Open("t:WBtest",MODE_NEWFILE)))
- >
-
- Create a set of routines that accept your file handle as
- input argument and make sure to call them only when
- the filehandle is valid:
-
- /*** writes "This" to file fh ***/
- BOOL WriteThis(BPTR fh)
- {
- UBYTE *str = "This\n";
- if (Write(fh, str, strlen(str)) > 0) return(TRUE);
- else return(FALSE);
- }
-
- /*** writes "That" to file fh ***/
- BOOL WriteThat(BPTR fh)
- {
- /* ... */
- }
-
- /*** creates a file with "This" and "That" in it ***/
- BOOL CreateFile(UBYTE *filename)
- {
-
- BPTR fh;
- BOOL success = FALSE;
-
- if (fh = Open(filename, MODE_NEWFILE)) {
- if(WriteThis(file)) {
- if (WriteThat(file)) {
- success = TRUE;
- };
- };
- Close(fh);
- };
- return(success);
- }
-
- Please do not use a global variable for the filehandle
- in such situations, as this will lead to certain confusion
- with more than 10*n functions spread over n source files.
-
- In two words: globals suck.
-
- ====//=== Andre Weissflog <floh@mkmk.in-chemnitz.de> =======
- ...// Sep'95: Return Of The Living Death...................
- \\// 90% of everything is crap (Sturgeon's Law)...........
- =\\===============================================Amiga!=
-
-